package com.example.springback.exception;

import com.example.springback.common.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
@ControllerAdvice("com.example.springback.controller")
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();
        return Result.error("500",e.getMessage());
    }
    @ExceptionHandler(CustomException.class)
    @ResponseBody
    public  Result errot(CustomException e){
        e.printStackTrace();
        return Result.error(e.getCode(),e.getMessage());
    }
}
